import 'dart:math';

import 'package:flutter/material.dart';

class GifTestPage extends StatefulWidget {
  const GifTestPage({super.key});

  @override
  State<GifTestPage> createState() => _GifTestPageState();
}

class _GifTestPageState extends State<GifTestPage> {
  void _incrementCounter() {
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ImageGrid(),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class ImageGrid extends StatelessWidget {
  const ImageGrid({super.key});

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      crossAxisCount: 4,
      children: List.generate(
        20,
        (i) => Image.asset(
          'assets/images/large.gif',
          key: ValueKey(i),
          // 尽量让每次创建的CachedNetworkImageProvider不唯一
          scale: Random.secure().nextDouble(),
        ),
      ),
    );
  }
}
